package com.order.itemcategoryproject.controller;

import com.order.itemcategoryproject.pojo.pArcStore;
import com.order.itemcategoryproject.service.pArcStoreService;
import com.order.itemcategoryproject.utils.AjaxResult;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static com.order.itemcategoryproject.utils.ParseUrl.getUrl;

@RestController
@RequestMapping("/store")
public class pArcStoreController {

    @Autowired
    private pArcStoreService pArcStoreService;


    /**
     * 根据加盟商编号获取当前加盟商下所有门店信息
     * @param request
     * @return
     */
    @GetMapping("/getAllStoreInfoByFranchisee")
    public AjaxResult selectAllStoreInfoByFranchisee(HttpServletRequest request){
        String queryString = request.getQueryString();
        String franchisee = getUrl(queryString, "StaffID");
        if (ObjectUtils.isEmpty(franchisee)) {
            return AjaxResult.error("参数未被定义!!!!!");
        }
        // 不为空，那么就可以直接获取当前加盟商下门店信息
        List<pArcStore> storeInfos = pArcStoreService.getAllStoreInfoByfranchisee(franchisee);
        if (ObjectUtils.isEmpty(storeInfos)) {
            return AjaxResult.error("当前加盟商下并没有关联门店信息!!!!");
        }
        return AjaxResult.success(storeInfos);
    }
}
